from django.db import models

from home.models import CateModel
from home.utils.BaseModel import BaseModel


# Create your models here.
class Teacher(BaseModel):
    name = models.CharField(max_length=100)
    job = models.CharField(max_length=100, verbose_name='职务')
    intro = models.TextField(verbose_name='简介')
    headimg = models.CharField(max_length=200)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'teacher'


class Course(BaseModel):
    name = models.CharField(max_length=100)
    teacher = models.ForeignKey(Teacher, on_delete=models.CASCADE)
    category = models.ForeignKey(CateModel, on_delete=models.CASCADE, verbose_name='课程分类')
    price = models.DecimalField(max_digits=10, decimal_places=2)
    timeline = models.CharField(max_length=90)
    counts = models.IntegerField(default=0)
    detail = models.TextField(default='')
    is_good = models.BooleanField(default=False)
    is_hot = models.BooleanField(default=False)
    is_home = models.BooleanField(default=False)
    level = models.IntegerField(default=0, choices=((1, '初级'), (2, '中级'), (3, '高级')))
    cover = models.CharField(max_length=200, default='')
    video = models.CharField(max_length=200, default='')
    score = models.FloatField(default=0)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'course'
